package mediatheque.view;

import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionListener;

import javax.swing.DefaultComboBoxModel;
import javax.swing.GroupLayout;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.LayoutStyle;

import mediatheque.model.MediathequeModel;
import mediatheque.model.PretModel;

public class RetourPretView extends JDialog {

	private static final long serialVersionUID = 316861042021923944L;

	protected MediathequeModel model;
	
    protected JButton btnAnnuler;
    protected JButton btnEnregistrer;
    protected JLabel lblTitre;
    protected JLabel lblPret;
    protected JLabel lbEtat;
    protected JTextField tfPret;  
    protected JComboBox cbEtat;

	protected PretModel pret; 

	
	
	public RetourPretView(MediathequeModel model, JFrame parent,PretModel pret) {
		super(parent, "Retour d'un pret", true);
		this.model = model;	
		this.pret = pret;
		setSize(440, 210);
		setLocationRelativeTo(null);
		setResizable(false);
        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
		
		initialiserComposants();		
	}

	protected void initialiserComposants() {
		DefaultComboBoxModel combo = new DefaultComboBoxModel();
		Font font = new java.awt.Font("Verdana", 0, 12);
		lblTitre = new JLabel("Retour d'un pret");
		lblTitre.setFont(font);
		lblPret = new JLabel("Pret : ");
		lblPret.setFont(font);
		tfPret = new JTextField(10);
		tfPret.setEditable(false);
		tfPret.setFont(font);
		tfPret.setText(pret.getIdentifiant());
		lbEtat = new JLabel("Etat : ");
		lbEtat.setFont(font);
		combo.addElement("Neuf");
		combo.addElement("Bon");
		combo.addElement("Moyen");
		combo.addElement("Mauvais");
		cbEtat = new JComboBox(combo);
		cbEtat.setFont(font);
        btnEnregistrer = new JButton("Enregistrer");
        btnEnregistrer.setFont(font);        
        btnAnnuler = new JButton("Annuler");
        btnAnnuler.setFont(font);
        
        
        placerComposants();
	}

	protected void placerComposants() {
		JPanel panneau = new JPanel(new GridBagLayout());
		GridBagConstraints gbc = new GridBagConstraints();
		
		gbc.gridx = 0;
		gbc.gridy = 0;
		gbc.gridwidth = GridBagConstraints.REMAINDER;
        gbc.anchor = GridBagConstraints.BASELINE_LEADING;
        gbc.insets = new Insets(30, 50, 30, 10);
        panneau.add(lblTitre, gbc);
		
		
		gbc.gridx = 0;
		gbc.gridy = 1;
        gbc.gridheight = gbc.gridwidth = 1;
        gbc.anchor = GridBagConstraints.BASELINE_LEADING;
        gbc.insets = new Insets(0, 10, 0, 0);
        panneau.add(lblPret, gbc);
		
        gbc.gridx = 1;
        gbc.gridwidth = 1;
        gbc.anchor = GridBagConstraints.BASELINE_LEADING;
        gbc.fill = GridBagConstraints.HORIZONTAL;
        gbc.insets = new Insets(0, 10, 0, 0);
        panneau.add(tfPret, gbc);

        gbc.gridx = 0;
        gbc.gridy = 2;
        gbc.gridwidth = 1;
        gbc.anchor = GridBagConstraints.BASELINE_LEADING;
        gbc.fill = GridBagConstraints.HORIZONTAL;
        gbc.insets = new Insets(10, 10, 0, 0);
        panneau.add(lbEtat, gbc);
        
        gbc.gridx = 1;
        gbc.gridwidth = 1;
        gbc.anchor = GridBagConstraints.BASELINE_LEADING;
        gbc.fill = GridBagConstraints.HORIZONTAL;
        gbc.insets = new Insets(10, 10, 0, 0);
        panneau.add(cbEtat, gbc);
        

        gbc.gridy = 3;
        gbc.gridx = 0;
        gbc.gridwidth = 1;
        gbc.anchor = GridBagConstraints.BASELINE_LEADING;
        gbc.fill = GridBagConstraints.HORIZONTAL;
        gbc.insets = new Insets(30, 0, 30, 30);
        panneau.add(btnEnregistrer, gbc);
        
        gbc.gridy = 3;
        gbc.gridx = 1;
        gbc.gridwidth = 1;
        gbc.anchor = GridBagConstraints.BASELINE_LEADING;
        gbc.fill = GridBagConstraints.HORIZONTAL;
        gbc.insets = new Insets(30, 0, 30, 30);
        panneau.add(btnAnnuler, gbc);
        
        
        getContentPane().add(panneau);
        
	}
	public void addEnregistrerListener(ActionListener al) {
		btnEnregistrer.addActionListener(al);
	}
	public void addAnnulerListener(ActionListener al) {
		btnAnnuler.addActionListener(al);
	}
	public String getValeurEtat() {
		return cbEtat.getSelectedItem().toString();
	}
}